<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\tk\controller;

use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;

class IndexController extends RestBaseController
{
    // tbk商品详情（简版）
    public function goodsDetail()
    {
        $app = tbk();
        $data = [
            'num_iids' => '123,456',//商品id串
            //'platform' => '1',//链接形式：1：PC，2：无线，默认：１
            //'ip'=>''
        ];
        $res = $app->item->getInfo($data);
        print_r($res);
    }

    /**
     * 推广券信息查询
     * @return array|mixed|\SimpleXMLElement|string
     */
    public function coupon()
    {
        $app = tbk();
        $data = [
            'item_id' => '123',//商品id
            //'activity_id' => '1',//券ID
            //'me' => '1',//带券ID与商品ID的加密串
        ];
        $res = $app->coupon->get($data);
        return $res;
    }

    /**
     * 淘抢购
     * @return array|mixed|\SimpleXMLElement|string
     */
    public function tqg()
    {
        $app = tbk();
        $data = [
            'adzone_id' => '123',//推广位id
            //需返回的字段列表
            'fields'=> 'click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time',
            //最早开团时间
            'start_time'=> '2016-08-09 09:00:00',
            //最晚开团时间
            'end_time'=>'2016-08-09 16:00:00',
            'page_no'=>1,//第几页
            'page_size'=>40,//页大小

        ];
        $res = $app->ju->getTqg($data);
        return $res;
    }

    /**
     * 使用通用物料 API 搜索产品 及获取榜单。在搜索产品时不传 material_id;在获取榜单时不传 q 关键词。
     *  'adzone_id' => '113418417',//mm_xxx_xxx_xxx的第三位
     *  'material_id'=> $params['mid'],//官方的物料Id
     *   'cat'=> '16,18',
     *   'q'=> $params['q'],//查询词
     * @return array|mixed|\SimpleXMLElement|string
     */
    public function materialOptional()
    {
        $app = tbk();
        $params['mid'] = input('mid',3786);
        //$params['q'] = input('q','');
        $params['cat'] = input('cat','16,18');
        $params['adzone_id'] = '113418417';
        $res = $app->dg->materialOptional($params);
        //print_r($res);die;
        return $res->result_list;
        $res = json_encode($res);
        $res = json_decode($res,true);
        return json_encode($res['result_list']);
    }
    /**
     * 使用通用物料 API 搜索产品 及获取榜单。在搜索产品时不传 material_id;在获取榜单时不传 q 关键词。
     * @return array|mixed|\SimpleXMLElement|string
     */
    public function kl()
    {
        $app = tbk();
        $params = input();
        print_r($params);
        $data = [
            'text'=> $params['text'],//口令弹框内容
            'url'=> $params['url'],//口令跳转目标页
            //'user_id' => '1',//生成口令的淘宝用户ID
            //'logo'=>3756,//口令弹框logoURL
            //'ext'=>'',//扩展字段JSON格式
        ];
        $res = $app->tpwd->create($data);
        return $res;
    }
}
